package router

import (
	"bms/control"
	"net/http"
)

func Run() {

	http.Handle("/pages/", http.StripPrefix("/pages/", http.FileServer(http.Dir("view/pages"))))
	http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("view/static"))))
	RouterGroup()
	http.ListenAndServe(":8080", nil)
}

func RouterGroup() {
	User()
	Book()
	Borrow()
}

func User() {
	http.HandleFunc("/main", control.Index)
	http.HandleFunc("/login", control.Login)
	http.HandleFunc("/checkUser", control.CheckUser)
	http.HandleFunc("/regist", control.Regist)
	http.HandleFunc("/logout", control.Logout)
	http.HandleFunc("/getAllUser", control.GetAllUser)
	http.HandleFunc("/reviseUser", control.ReviseUser)
	http.HandleFunc("/deleteUser", control.DeleteUser)

}
func Book() {
	http.HandleFunc("/getBook", control.GetBook)
	http.HandleFunc("/getBookByPage", control.GetBookByPage)
	http.HandleFunc("/getBookByTitleOrAuthor", control.GetBookByTitleOrAuthor)
	http.HandleFunc("/queryBookById", control.QueryBookById)
	http.HandleFunc("/editBook", control.EditBook)
	http.HandleFunc("/deleteBookById", control.DeleteBookById)
}

func Borrow() {
	http.HandleFunc("/borrowBook", control.BorrowBook)
	http.HandleFunc("/getBorrowRecord", control.GetBorrowRecord)
	http.HandleFunc("/returnBook", control.ReturnBook)
}
